Skip to content

ci: PR 생성 시 codex/claude 자동 코드리뷰 워크플로우 추가 - #19

Merged
eottabom merged 3 commits into
mainfrom
feature/pr-auto-review
Aug 8, 2026
Merged

ci: PR 생성 시 codex/claude 자동 코드리뷰 워크플로우 추가#19
eottabom merged 3 commits into
mainfrom
feature/pr-auto-review

Conversation

@eottabom

@eottabom eottabom commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • pull_request: [opened, ready_for_review]claude-review/codex-review 잡을 병렬로 실행
  • PR 코멘트에 @eottabom-review-bot을 멘션하면 같은 두 잡을 다시 실행 (pr-mention-review.yml)
  • 두 잡 모두 pulls/{pr}/reviews API로 정식 GitHub 리뷰(종합 평가 표 + 인라인 코멘트)를 남김
  • 별도 봇 계정/PAT 없이 기본 GITHUB_TOKEN으로 동작 (코멘트 작성자는 github-actions[bot], 본문 헤더에 eottabom-review-bot 브랜딩)
  • 러너 작업 디렉터리/HOME은 워크플로우에 하드코딩하지 않고 리포지토리 Variable(vars.RUNNER_WORKDIR, vars.RUNNER_HOME)로 분리 — public 저장소에 로컬 경로가 노출되지 않도록 함 (이미 gh variable set으로 등록 완료)
  • undefined-lab/codex review, /claude review 슬래시 커맨드 잡 로직을 재사용하되, 수동 트리거 대신 PR 생성/멘션 시 자동 실행되도록 변경

필요 사전 작업 (이 PR만으로는 동작 안 함)

  • sandbox-load-test에 self-hosted mac 러너([self-hosted, macOS, X64]) 등록 필요 — 현재 이 저장소엔 러너가 없음
  • 러너 머신에 claude/codex CLI 로그인 세션 필요

Closes #https://github.com/eottabom/engineering-log/issues/457

Test plan

  • 러너 등록 후 PR open 시 두 리뷰가 정상적으로 달리는지 확인
  • PR 코멘트에 @eottabom-review-bot 멘션 시 재리뷰가 도는지 확인
  • claude 로그인 만료 시 경고 코멘트가 정상적으로 달리는지 확인

pull_request opened 이벤트에서 claude-review, codex-review 잡을
병렬로 실행해 pulls/reviews API로 정식 GitHub 리뷰를 남긴다.
undefined-lab의 슬래시 커맨드 리뷰 잡 패턴을 재사용하되 수동 트리거
대신 PR 생성 시 자동으로 동작하도록 구성했다.

Closes #457
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

고수준 검토 요약

워크플로는 자동 리뷰 실행 경로를 추가하지만, 현재 구현은 외부 PR에서 self-hosted runner와 저장소 쓰기 권한을 함께 사용합니다. PR 브랜치의 변경 내용이 리뷰 실행 환경에 영향을 줄 수 있으므로 보안 위험이 큽니다. 또한 Claude와 Codex CLI의 로그인 상태, JSON 출력, API 게시 실패를 충분히 검증하지 않으면 리뷰가 조용히 누락될 수 있습니다.

인라인 리뷰

.github/workflows/pr-auto-review.yml

  • self-hosted runner에서 PR 코드를 체크아웃하지 마십시오. 외부 기여자의 PR 코드가 runner의 기존 파일, CLI 세션, 토큰에 접근할 수 있습니다. 신뢰된 브랜치만 실행하거나 격리된 ephemeral runner를 사용하십시오.
  • PR 작성자의 변경 내용에 대해 pull_request_target과 동일한 수준의 권한을 부여하지 마십시오. BOT_TOKENpull-requests: write 권한을 함께 사용하면 악성 PR이 리뷰 환경을 통해 토큰을 탈취할 수 있습니다.
  • ready_for_review 이벤트와 비초안 조건의 동작을 명시적으로 검증하십시오. draft에서 ready 상태로 전환될 때만 실행되는지 확인하고, 동일 PR의 반복 실행이 이전 실행과 충돌하지 않도록 하십시오.
  • Claude 로그인 실패 외에 Codex 로그인 실패도 처리하십시오. Codex 세션이 만료되면 작업이 실패하지만 PR 작성자에게 원인이 전달되지 않을 수 있습니다.
  • CLI 출력의 JSON 파싱 결과를 검증하십시오. 필수 필드와 라인 번호를 검증한 뒤 GitHub API를 호출해야 잘못된 리뷰가 게시되지 않습니다.

.github/scripts/claude-review-run.sh

  • PR 번호와 기준 브랜치를 셸 명령 인자로 직접 조합하지 마십시오. 입력값을 검증하고 프롬프트 파일에 안전하게 전달하십시오. 프롬프트에는 다음과 같은 안전한 구분자를 사용하십시오.
pr_number="${1:?PR number is required}"
base_ref="${2:?Base ref is required}"

case "$pr_number" in
  ''|*[!0-9]*) echo "Invalid PR number" >&2; exit 1 ;;
esac

case "$base_ref" in
  ''|*[!A-Za-z0-9_./-]*) echo "Invalid base ref" >&2; exit 1 ;;
esac
  • Claude CLI의 종료 코드와 결과 파일을 확인하십시오. CLI가 성공 코드로 종료해도 빈 파일 또는 잘못된 JSON을 생성할 수 있습니다. test -s와 JSON 파싱 검사를 추가하십시오.
  • 리뷰 게시를 프롬프트 지시에만 의존하지 마십시오. 스크립트가 API 게시를 직접 수행하거나, 최소한 결과 JSON의 event, body, comments[].path, comments[].line을 검증해야 합니다.
  • 전체 diff를 프롬프트에 직접 삽입하는 방식은 크기 제한을 만들 수 있습니다. 큰 PR에서 프롬프트가 CLI 또는 모델 입력 제한을 초과할 수 있으므로 diff를 파일로 제공하고 크기 제한 및 절단 정책을 명시하십시오.

.github/scripts/codex-review-run.sh

  • --dangerously-bypass-approvals-and-sandbox 사용을 제거하십시오. self-hosted runner에서 실행되는 PR 코드는 Codex 실행을 통해 임의 명령을 수행할 수 있습니다. 필요한 작업 디렉터리와 읽기 전용 입력만 허용하는 별도 격리 환경을 사용하십시오.
  • Codex 실행 전 환경 변수를 제한하십시오. 기존 runner 환경에 저장된 인증 정보가 프롬프트 처리 과정에 노출될 수 있습니다. 필요한 변수만 명시적으로 전달하십시오.
  • Codex의 종료 코드와 출력 JSON을 검증하십시오. 결과 파일이 없거나 JSON 구조가 잘못된 경우 후속 API 게시를 중단하고 명확한 오류를 반환해야 합니다.
  • 임시 파일 정리 트랩의 실패 경로를 확인하십시오. set -u 환경에서 초기화되지 않은 임시 파일 변수를 참조하지 않도록 변수 초기화 순서를 보장하십시오.
  • 리뷰 결과를 CLI가 직접 GitHub API에 게시하도록 요구하지 마십시오. 모델이 생성한 API 호출은 재현성과 검증이 어렵습니다. Codex는 구조화된 결과만 생성하고, 별도의 고정된 스크립트가 검증 후 API를 호출해야 합니다.

Walkthrough

Pull Request 이벤트에 반응하는 자동 리뷰 워크플로를 추가했습니다. 워크플로는 Claude와 Codex 리뷰를 병렬 실행하고, 각 리뷰 스크립트는 한국어 JSON 리뷰를 생성해 GitHub Pull Request 리뷰 API에 게시하도록 CLI를 실행합니다.

Changes

Pull Request 자동 리뷰

Layer / File(s) Summary
리뷰 실행 스크립트
.github/scripts/claude-review-run.sh, .github/scripts/codex-review-run.sh
Claude와 Codex가 프로젝트 지침, 변경 파일, 전체 diff를 확인하도록 프롬프트를 구성합니다. 리뷰 결과를 지정된 JSON 형식으로 작성하고 GitHub Pull Request 리뷰 API에 게시하도록 CLI를 실행합니다.
워크플로 트리거와 Claude 인증
.github/workflows/pr-auto-review.yml
비초안 Pull Request 이벤트를 처리하고 PR별 동시 실행 그룹과 실행 제한을 설정합니다. Claude CLI 인증이 없으면 Pull Request에 재로그인 안내를 게시합니다.
리뷰 작업 실행과 출력 처리
.github/workflows/pr-auto-review.yml
인증된 경우 Claude 리뷰를 실행하고 JSON 스트림을 텍스트, 도구 호출, 결과 형식으로 출력합니다. 별도 Codex 작업은 Pull Request 브랜치를 원격 기준으로 동기화한 뒤 Codex 리뷰 스크립트를 실행합니다.

Estimated code review effort: 4 (Complex) | ~45분

Sequence Diagram(s)

sequenceDiagram
  participant PullRequest
  participant GitHubActions
  participant ClaudeCLI
  participant CodexCLI
  participant GitHubReviewAPI

  PullRequest->>GitHubActions: 열림 또는 리뷰 준비 이벤트
  GitHubActions->>ClaudeCLI: Claude 리뷰 작업 실행
  ClaudeCLI->>GitHubReviewAPI: JSON 리뷰 게시
  GitHubActions->>CodexCLI: Codex 리뷰 작업 실행
  CodexCLI->>GitHubReviewAPI: JSON 리뷰 게시
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 제목이 PR의 주요 변경 사항인 Codex 및 Claude 자동 코드리뷰 워크플로 추가를 정확하고 간결하게 설명합니다.
Description check ✅ Passed 작업 내용, 관련 이슈, 사전 작업, 테스트 계획을 포함하며 PR 목적과 구현 범위를 구체적으로 설명합니다.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/pr-auto-review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5c257814-b0cc-4fb2-8baa-056033c4a8b3

📥 Commits

Reviewing files that changed from the base of the PR and between 4996c8b and ec80aca.

📒 Files selected for processing (3)
  • .github/scripts/claude-review-run.sh
  • .github/scripts/codex-review-run.sh
  • .github/workflows/pr-auto-review.yml
📜 Review details
🧰 Additional context used
🪛 actionlint (1.7.12)
.github/workflows/pr-auto-review.yml

[error] 29-29: "github.event.pull_request.head.ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks for more details

(expression)


[error] 90-90: "github.event.pull_request.head.ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks for more details

(expression)

🪛 zizmor (1.29.0)
.github/workflows/pr-auto-review.yml

[error] 9-9: overly broad permissions (excessive-permissions): pull-requests: write is overly broad at the workflow level

(excessive-permissions)


[warning] 30-30: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 32-32: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 32-32: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 32-32: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 33-33: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[warning] 91-91: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 93-93: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 93-93: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 93-93: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 94-94: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[warning] 9-9: permissions without explanatory comments (undocumented-permissions): needs an explanatory comment

(undocumented-permissions)


[info] 12-12: workflow or action definition without a name (anonymous-definition): this job

(anonymous-definition)


[info] 73-73: workflow or action definition without a name (anonymous-definition): this job

(anonymous-definition)

Comment thread .github/scripts/claude-review-run.sh
Comment thread .github/workflows/pr-auto-review.yml Outdated
Comment thread .github/workflows/pr-auto-review.yml Outdated
Comment thread .github/workflows/pr-auto-review.yml Outdated
- 러너 작업 디렉터리/HOME을 vars.RUNNER_WORKDIR, vars.RUNNER_HOME으로 분리해
  public 저장소 워크플로우 파일에 로컬 사용자 경로가 노출되지 않게 한다.
- 별도 봇 계정 PAT 없이 기본 GITHUB_TOKEN으로 리뷰 코멘트를 남기도록 단순화.
- PR 코멘트에 @eottabom-review-bot을 멘션하면 claude/codex 리뷰를
  다시 실행하는 pr-mention-review.yml 추가.
- git checkout에 PR head.ref를 직접 셸 확장하던 부분을 제거하고
  refs/pull/<n>/head fetch + head_sha 검증으로 대체해 브랜치명을 통한
  템플릿/셸 인젝션 가능성을 없앤다.
- origin remote에 남아있던 토큰을 fetch 직후 제거해 영구 작업 디렉터리에
  자격증명이 남지 않게 한다.
- claude-review 잡의 파이프라인 `|| true`가 claude 실행 자체의 실패까지
  삼키던 문제를 set +e/PIPESTATUS로 교체해 claude 스크립트의 실제
  종료 코드만 잡의 성패로 반영한다.
- codex-review에도 claude-review와 동일한 CLI 로그인 상태 사전 점검과
  만료 알림 코멘트를 추가한다.
- PR 작성자/코멘트 작성자가 OWNER/MEMBER/COLLABORATOR가 아니면
  자동/멘션 리뷰가 실행되지 않도록 제한해, 외부 PR이 self-hosted
  러너에서 신뢰되지 않은 스크립트를 실행하는 범위를 줄인다.
@eottabom
eottabom merged commit 066a67c into main Aug 8, 2026
1 check passed
@eottabom
eottabom deleted the feature/pr-auto-review branch August 8, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant